package com.woniuxy.yuekeuser.dao;

import com.woniuxy.yuekeuser.model.CampsiteActivity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniuxy.yuekeuser.model.CampsiteActivityPicture;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Freedom
 * @since 2020-11-03
 */
public interface CampsiteActivityMapper extends BaseMapper<CampsiteActivity> {
    /**
     * 新增营地活动
     * @param campsiteActivity
     * @return
     */
    @Insert("insert into campsite_activity (campsite_activity_name,campsite_id,campsite_activity_words) values(#{campsiteActivityName},#{campsiteId},#{campsiteActivityWords})")
    @Options(useGeneratedKeys = true,keyProperty = "campsiteActivityId")
    public void addCampsiteActivity(CampsiteActivity campsiteActivity);


    /**
     * 营地活动图片表新增数据
     * @param campsiteActivityPicture
     */
    @Insert("insert into campsite_activity_picture (campsite_activity_picture_address,campsite_activity_id) value(#{campsiteActivityPictureAddress},#{campsiteActivityId})")
    public void addcampsiteActivityPicture(CampsiteActivityPicture campsiteActivityPicture);

    /**
     * 动态查询营地活动
     */
    public List<CampsiteActivity> findActivitys(String campsiteName,int index, int pageSize);

    /**
     * 动态查询营地活动条数
     */
    public int findActivityCount(String campsiteName);

    /**
     * 根据活动id查询活动图片
     */
    @Select("select campsite_activity_picture_id,campsite_activity_picture_address,campsite_activity_id from campsite_activity_picture where campsite_activity_id = #{id} ")
    public List<CampsiteActivityPicture> findActivityImagesByActivityId(int id);

    /**
     * 根据活动id查询该活动的第一张图片
     */
    @Select("select campsite_activity_picture_address  from campsite_activity_picture where campsite_activity_id = #{id} limit 0,1 ")
    public String findImageByActivityId(int id);

}
